package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MineUserPlaybackRecord;
import com.ruoyi.system.service.IMineUserPlaybackRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户播放记录Controller
 * 
 * @author ruoyi
 * @date 2025-01-14
 */
@RestController
@RequestMapping("/system/record")
public class MineUserPlaybackRecordController extends BaseController
{
    @Autowired
    private IMineUserPlaybackRecordService mineUserPlaybackRecordService;

    /**
     * 查询用户播放记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(MineUserPlaybackRecord mineUserPlaybackRecord)
    {
        startPage();
        List<MineUserPlaybackRecord> list = mineUserPlaybackRecordService.selectMineUserPlaybackRecordList(mineUserPlaybackRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户播放记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "用户播放记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MineUserPlaybackRecord mineUserPlaybackRecord)
    {
        List<MineUserPlaybackRecord> list = mineUserPlaybackRecordService.selectMineUserPlaybackRecordList(mineUserPlaybackRecord);
        ExcelUtil<MineUserPlaybackRecord> util = new ExcelUtil<MineUserPlaybackRecord>(MineUserPlaybackRecord.class);
        util.exportExcel(response, list, "用户播放记录数据");
    }

    /**
     * 获取用户播放记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(mineUserPlaybackRecordService.selectMineUserPlaybackRecordByRecordId(recordId));
    }

    /**
     * 根据 userId 查询用户播放记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/user/{userId}")
    public AjaxResult getInfoByUserId(@PathVariable("userId") Long userId)
    {
        return success(mineUserPlaybackRecordService.selectMineUserPlaybackRecordByUserId(userId));
    }

    /**
     * 根据 videoId 查询用户播放记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/video/{videoId}")
    public AjaxResult getInfoByVideoId(@PathVariable("videoId") Long videoId)
    {
        return success(mineUserPlaybackRecordService.selectMineUserPlaybackRecordByVideoId(videoId));
    }
    /**
     * 根据 trainingId 查询用户播放记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/training/{trainingId}")
    public AjaxResult getInfoByTrainingId(@PathVariable("trainingId") Long trainingId)
    {
        return success(mineUserPlaybackRecordService.selectMineUserPlaybackRecordByTrainingId(trainingId));
    }

    /**
     * 新增用户播放记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "用户播放记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MineUserPlaybackRecord mineUserPlaybackRecord)
    {
        return toAjax(mineUserPlaybackRecordService.insertMineUserPlaybackRecord(mineUserPlaybackRecord));
    }

    /**
     * 修改用户播放记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "用户播放记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MineUserPlaybackRecord mineUserPlaybackRecord)
    {
        return toAjax(mineUserPlaybackRecordService.updateMineUserPlaybackRecord(mineUserPlaybackRecord));
    }

    /**
     * 删除用户播放记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "用户播放记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(mineUserPlaybackRecordService.deleteMineUserPlaybackRecordByRecordIds(recordIds));
    }
}
